#!/bin/bash
. /opt/hygon/common.sh

os_release=$(eval get_os_release)

if [ $os_release == "centos" ];then
	source /opt/rh/devtoolset-8/enable
fi

cp /boot/config-$(uname -r) .config
./scripts/config --enable CONFIG_AMD_MEM_ENCRYPT
./scripts/config --enable CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT
./scripts/config --set-str SYSTEM_TRUSTED_KEYS ""
./scripts/config --disable CONFIG_DEBUG_INFO_BTF
./scripts/config --disable CONFIG_DEBUG_INFO
yes "" | make olddefconfig


mkdir -p /opt/hygon/csv/kernel
rm -rf /opt/hygon/csv/kernel/*

os_release=$(eval get_os_release)
case $os_release in
     "anolis" | "centos")
	     rm -rf ~/rpmbuild/RPMS/x86_64/kernel-*.rpm
	     make -j$(getconf _NPROCESSORS_ONLN) LOCALVERSION="-csv" rpm-pkg
	     mv ~/rpmbuild/RPMS/x86_64/kernel-*.rpm /opt/hygon/csv/kernel/
             ;;
     "ubuntu")
	     rm -rf ../linux-*-csv*.deb
	     make -j$(getconf _NPROCESSORS_ONLN) LOCALVERSION="-csv" bindeb-pkg
	     mv ../linux-*-csv*.deb  /opt/hygon/csv/kernel/
             ;;
     esac

cd /opt/hygon/csv/
tar czvf kernel.tgz kernel
